package com.yl.danmo.service.impl;


import com.alibaba.nacos.api.model.v2.Result;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.yl.common.core.utils.DateUtils;
import com.yl.danmo.controller.DanmoInformationCalligrapherPositionController;
import com.yl.danmo.controller.DanmoPersonPositionController;
import com.yl.danmo.domain.*;
import com.yl.danmo.mapper.DanmoInformationCalligrapherPositionMapper;
import com.yl.danmo.mapper.DanmoInformationGuoMapper;
import com.yl.danmo.mapper.DanmoPersonPositionMapper;
import com.yl.danmo.service.IDanmoInformationGuoService;
import com.yl.danmo.service.IDanmoPersonInfo0Service;
import com.yl.danmo.service.IDanmoPersonInfo1Service;
import com.yl.danmo.service.IDanmoPersonInfo2Service;
import org.apache.catalina.security.SecurityUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员信息 国家级Service业务层处理
 * 
 * @author yl
 * @date 2025-04-12
 */
@Service
public class DanmoInformationGuoServiceImpl implements IDanmoInformationGuoService
{
    @Autowired
    private DanmoInformationGuoMapper danmoInformationGuoMapper;

    /**
     * 查询会员信息 国家级
     * 
     * @param id 会员信息 国家级主键
     * @return 会员信息 国家级
     */
    @Override
    public DanmoInformationGuo selectDanmoInformationGuoById(Long id)
    {
        return danmoInformationGuoMapper.selectDanmoInformationGuoById(id);
    }

    /**
     * 查询会员信息 国家级列表
     * 
     * @param danmoInformationGuo 会员信息 国家级
     * @return 会员信息 国家级
     */
    @Override
    public List<DanmoInformationGuo> selectDanmoInformationGuoList(DanmoInformationGuo danmoInformationGuo)
    {
        return danmoInformationGuoMapper.selectDanmoInformationGuoList(danmoInformationGuo);
    }

    /**
     * 新增会员信息 国家级
     * 
     * @param danmoInformationGuo 会员信息 国家级
     * @return 结果
     */
    @Override
    public int insertDanmoInformationGuo(DanmoInformationGuo danmoInformationGuo)
    {
        danmoInformationGuo.setCreateTime(DateUtils.getNowDate());
        return danmoInformationGuoMapper.insertDanmoInformationGuo(danmoInformationGuo);
    }

    /**
     * 修改会员信息 国家级
     * 
     * @param danmoInformationGuo 会员信息 国家级
     * @return 结果
     */
    @Override
    public int updateDanmoInformationGuo(DanmoInformationGuo danmoInformationGuo)
    {
        danmoInformationGuo.setUpdateTime(DateUtils.getNowDate());
        return danmoInformationGuoMapper.updateDanmoInformationGuo(danmoInformationGuo);
    }

    /**
     * 批量删除会员信息 国家级
     * 
     * @param ids 需要删除的会员信息 国家级主键
     * @return 结果
     */
    @Override
    public int deleteDanmoInformationGuoByIds(Long[] ids)
    {
        return danmoInformationGuoMapper.deleteDanmoInformationGuoByIds(ids);
    }

    /**
     * 删除会员信息 国家级信息
     * 
     * @param id 会员信息 国家级主键
     * @return 结果
     */
    @Override
    public int deleteDanmoInformationGuoById(Long id)
    {
        return danmoInformationGuoMapper.deleteDanmoInformationGuoById(id);
    }

    @Autowired
    private IDanmoPersonInfo0Service danmoPersonInfo0Service;
    @Autowired
    private IDanmoPersonInfo1Service danmoPersonInfo1Service;
    @Autowired
    private IDanmoPersonInfo2Service danmoPersonInfo2Service;
    @Autowired
    private DanmoPersonPositionMapper danmoPersonPositionMapper;

    @Autowired
    private DanmoInformationCalligrapherPositionMapper danmoInformationCalligrapherPositionMapper;
    @Override
    public int clean(DanmoInformationGuo danmoInformationGuo) {
        List<DanmoInformationGuo> danmoInformationGuos = selectDanmoInformationGuoList(danmoInformationGuo);
        for (DanmoInformationGuo danmoInformationGuo1 : danmoInformationGuos) {
            Long id = danmoInformationGuo1.getId();

            if (id %3==0){
                DanmoPersonInfo0 danmoPersonInfo0 = new DanmoPersonInfo0();
//                danmoPersonInfo0.setId(IdWorker.getId());
                danmoPersonInfo0.setId(danmoInformationGuo1.getId());
                danmoPersonInfo0.setUserId(danmoInformationGuo1.getUserId());
                danmoPersonInfo0.setName(danmoInformationGuo1.getName());
                danmoPersonInfo0.setDynastiesId(danmoInformationGuo1.getDynastiesId());
                danmoPersonInfo0.setBasicId(danmoInformationGuo1.getBasicId());
                danmoPersonInfo0Service.insertDanmoPersonInfo0(danmoPersonInfo0);
            }
            if (id %3==1){
                DanmoPersonInfo1 danmoPersonInfo0 = new DanmoPersonInfo1();
//                danmoPersonInfo0.setId(IdWorker.getId());
                danmoPersonInfo0.setId(danmoInformationGuo1.getId());
                danmoPersonInfo0.setUserId(danmoInformationGuo1.getUserId());
                danmoPersonInfo0.setName(danmoInformationGuo1.getName());
                danmoPersonInfo0.setDynastiesId(danmoInformationGuo1.getDynastiesId());
                danmoPersonInfo0.setBasicId(danmoInformationGuo1.getBasicId());
                danmoPersonInfo1Service.insertDanmoPersonInfo1(danmoPersonInfo0);
            }
            if (id %3==2){
                DanmoPersonInfo2 danmoPersonInfo0 = new DanmoPersonInfo2();
//                danmoPersonInfo0.setId(IdWorker.getId());
                danmoPersonInfo0.setId(danmoInformationGuo1.getId());
                danmoPersonInfo0.setUserId(danmoInformationGuo1.getUserId());
                danmoPersonInfo0.setName(danmoInformationGuo1.getName());
                danmoPersonInfo0.setDynastiesId(danmoInformationGuo1.getDynastiesId());
                danmoPersonInfo0.setBasicId(danmoInformationGuo1.getBasicId());
                danmoPersonInfo2Service.insertDanmoPersonInfo2(danmoPersonInfo0);
            }

            DanmoPersonPosition danmoPersonPosition = new DanmoPersonPosition();
            danmoPersonPosition.setId(IdWorker.getId());
            danmoPersonPosition.setPersonId(danmoInformationGuo1.getId());
            danmoPersonPosition.setAssociationId(danmoInformationGuo1.getAssociation());
            danmoPersonPosition.setAssociationTypeId(danmoInformationGuo1.getAssociationType());
            danmoPersonPosition.setSeveral(danmoInformationGuo1.getSeveral());
            danmoPersonPosition.setYear(danmoInformationGuo1.getYear());
            danmoPersonPosition.setPositions(danmoInformationGuo1.getPositions());
            danmoPersonPosition.setMassId(danmoInformationGuo1.getMassId());
            danmoPersonPosition.setAddressCity(danmoInformationGuo1.getAddressCity());
            danmoPersonPosition.setAddressCounty(danmoInformationGuo1.getAddressCounty());
            danmoPersonPosition.setAddressEntry(danmoInformationGuo1.getAddressEntry());


            DanmoInformationCalligrapherPosition danmoInformationCalligrapherPosition=   danmoInformationCalligrapherPositionMapper.selectId(danmoInformationGuo1.getId());
            if (danmoInformationCalligrapherPosition!=null){
                if (danmoInformationCalligrapherPosition.getPositionId()!=null){
                    danmoPersonPosition.setPositionId(danmoInformationCalligrapherPosition.getPositionId());
                }
            }

            danmoPersonPositionMapper.insertDanmoPersonPosition(danmoPersonPosition);
        }

        return 1;
    }
}
